package com.atguigu.bigdata.scala.chapter07

import scala.io.{BufferedSource, Source}

object Scala11_Collection_WordCount_1 {

    def main(args: Array[String]): Unit = {

        // TODO - WordCount
        val source: BufferedSource = Source.fromFile("data/word.txt")
        val list: List[String] = source.getLines().toList
        source.close()

        list
            .flatMap(_.split(" "))
            .groupBy( word=>word ) // 如果参数原封不动返回，那么不能简化
            .map(t => {(t._1, t._2.size)})
            .toList
            .sortBy(_._2)(Ordering.Int.reverse)
            .take(3)
            .foreach(println)

    }
}
